function getAJAXObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
		catch(e){
			// Internet Explorer
			try{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e){
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
						}
			}
	return xmlHttp;
	}

//---------------------------------------------------------------------------------------------
var AJAX_signState;

var xmlDoc;

function checkSignState(callBack){
	AJAX_signState = getAJAXObject();
	if(AJAX_signState==null){
		alert ("Browser does not support HTTP Request,Please change your Browser!");
		return;
		}
		var url="http://www.eizia.com/login.php";
		url = url +"?sid="+Math.random();
		AJAX_signState.onreadystatechange = function(){signStateOrder(callBack);};
		AJAX_signState.open("POST",url,true);
		AJAX_signState.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
		AJAX_signState.send("state=signState");
	}
function signStateOrder(callBack){
	if (AJAX_signState.readyState==4 || AJAX_signState.readyState=="complete")
		{ 
		xmlDoc = AJAX_signState.responseXML;
		var signState = xmlDoc.getElementsByTagName("signState");
		var info = signState[0] ? signState[0] : false;
		if(info){
			if(info.childNodes[0].childNodes[0].nodeValue=="ready"){
				//startUserTabs(true);
				callBack(true);
				$("#userTabs_title").hide();
				$("#welcomeInfo").hide();
				$("#userTips").show();
				user_id = info.childNodes[1].childNodes[0].nodeValue;
				userName = info.childNodes[2].childNodes[0].nodeValue;
				model_id = info.childNodes[3].childNodes[0] ? info.childNodes[3].childNodes[0].nodeValue : null;
				//document.getElementById("userNameSpace").innerHTML = userName;
				}
			else if(info.childNodes[0].childNodes[0].nodeValue=="nobody"){
				//startUserTabs(false);
				callBack(false);
				$("#userTabs_title").show();
				$("#welcomeInfo").show();
				$("#userTips").hide();
				}
			}
		} 
	}
	
	
var AJAX_sign;

function loginToServer(userName,password){
	var password = MD5(password);
	AJAX_sign = getAJAXObject();
	if(AJAX_sign==null){
		alert ("Browser does not support HTTP Request,Please change your Browser!");
		return;
		}
	document.getElementById("signIning").src = "http://www.eizia.com/webpic/ing.gif";
	document.getElementById("loginInfo").innerHTML = "";
	if(userName && password){
		var url="http://www.eizia.com/login.php";
		url = url +"?sid="+Math.random();
		AJAX_sign.onreadystatechange = afterLogin;
		AJAX_sign.open("POST",url,true);
		AJAX_sign.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
		AJAX_sign.send("state=loginIn&"+
				  "userName="+userName+"&"+
				  "password="+password);
		}
	}
function afterLogin(){
	if (AJAX_sign.readyState==4 || AJAX_sign.readyState=="complete")
		{ 
		xmlDoc = AJAX_sign.responseXML;
		var saveModel = xmlDoc.getElementsByTagName("loginIn");
		var info = saveModel[0] ? saveModel[0] : false;
		if(info){
			if(info.childNodes[0].childNodes[0].nodeValue=="ok"){
				document.getElementById("signIning").src = "http://www.eizia.com/webpic/blank.png";
				document.getElementById('login').password.value = "";
				user_id = info.childNodes[1].childNodes[0].nodeValue;
				userName = info.childNodes[2].childNodes[0].nodeValue;
				document.getElementById("userNameSpace").innerHTML = userName;
				//切换显示的div
				$("#userTabs_title").tabs({
						select:function(event,ui){
								$(ui.panel).toggle("blind",{},150,function(){
															$("#userTabs_title").hide();
															$("#userTips").show();
													});
							}
					});
				$("#userTabs_title").tabs( "option", "selected", -1 );
				$("#userTabs_title").tabs({
						select:function(event,ui){
							var selected = $(this).tabs("option","selected");
							var touch = ui.index;
							if( selected<0){
								$("#welcomeInfo").toggle("blind",{},150);
								$(ui.panel).toggle("blind",{},150);
								}
							else if(selected==touch){
								$("#welcomeInfo").toggle("blind",{},150);
								$(ui.panel).toggle("blind",{},150);
								}
							else if(selected!=touch){
								$("div#userTabs_title div:nth-child("+(selected+2)+")").hide();
								$("div#userTabs_title div:nth-child("+(touch+2)+")").show();
								}
							}
					});
				}
			else if(info.childNodes[0].childNodes[0].nodeValue=="wrong"){
				document.getElementById("signIning").src = "http://www.eizia.com/webpic/warning.png";
				document.getElementById("loginInfo").innerHTML = "用户名或者密码错";
				}
			else if(info.childNodes[0].childNodes[0].nodeValue=="ready"){
				document.getElementById("signIning").src = "http://www.eizia.com/webpic/warning.png";
				document.getElementById("loginInfo").innerHTML = "已经有账户登录了";
				}
			}
		} 
	}
	
function offServer(){
	AJAX_sign = getAJAXObject();
	if(AJAX_sign==null){
		alert ("Browser does not support HTTP Request,Please change your Browser!");
		return;
		}
	document.getElementById("offLining").src = "http://www.eizia.com/webpic/ing.gif";
		var url="http://www.eizia.com/login.php";
		url = url +"?sid="+Math.random();
		AJAX_sign.onreadystatechange = offStateTips;
		AJAX_sign.open("POST",url,true);
		AJAX_sign.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
		AJAX_sign.send("state=loginOut");
	}
function offStateTips(){
	if (AJAX_sign.readyState==4 || AJAX_sign.readyState=="complete")
		{ 
		xmlDoc = AJAX_sign.responseXML;
		var saveModel = xmlDoc.getElementsByTagName("loginOut");
		var info = saveModel[0] ? saveModel[0] : false;
		if(info){
			if(info.childNodes[0].childNodes[0].nodeValue=="offSuccess"){
				document.getElementById("userNameSpace").innerHTML = "";
				document.getElementById("offLining").src = "http://www.eizia.com/webpic/blank.png";
				$("#welcomeInfo").show("blind",{},200);
				$("#userTabs_title").show();
				$("#userTips").hide();
				}
			}
		} 
	}
//---------------------------------------------------------------------------------------------

var AJAX_submit;

function userApp(userName,password,rePassword,email){
	if(	document.getElementById("checkNameing").src == "http://www.eizia.com/webpic/correct.png" && 
		document.getElementById("passwordCheckImg").src == "http://www.eizia.com/webpic/correct.png" && 
		document.getElementById("repasswordCheckImg").src == "http://www.eizia.com/webpic/correct.png" && 
		document.getElementById("mailAds").src == "http://www.eizia.com/webpic/correct.png"
		){
		var password = MD5(password);
		AJAX_submit = getAJAXObject();
		if(AJAX_submit==null){
			alert ("Browser does not support HTTP Request,Please change your Browser!");
			return;
			}
		document.getElementById("signUping").src = "http://www.eizia.com/webpic/ing.gif";
		if(userName && password && rePassword && email){
			var url="http://www.eizia.com/application.php";
			url = url +"?sid="+Math.random();
			AJAX_submit.onreadystatechange = appStateTips;
			AJAX_submit.open("POST",url,true);
			AJAX_submit.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
			AJAX_submit.send("state=application"+"&"+
							 "userName="+userName+"&"+
							 "password="+password+"&"+
							 "email="+email);
			}
		}
	}
function appStateTips(){
	if (AJAX_submit.readyState==4 || AJAX_submit.readyState=="complete")
		{
		xmlDoc = AJAX_submit.responseXML;
		var saveModel = xmlDoc.getElementsByTagName("application");
		var info = saveModel[0] ? saveModel[0] : false;
		if(info){
			if(info.childNodes[0].childNodes[0].nodeValue=="ok"){
				document.getElementById("signUping").src = "http://www.eizia.com/webpic/blank.png";
				document.getElementById('application').password.value = "";
				document.getElementById('application').rePassword.value = "";
				user_id = info.childNodes[1].childNodes[0].nodeValue;
				userName = info.childNodes[2].childNodes[0].nodeValue;
				document.getElementById("userNameSpace").innerHTML = userName;
				//切换显示的div
				$("#userTabs_title").tabs({
						select:function(event,ui){
								$(ui.panel).toggle("blind",{},150,function(){
															$("#userTabs_title").hide();
															$("#userTips").show();
													});
							}
					});
				$("#userTabs_title").tabs( "option", "selected", -1 );
				$("#userTabs_title").tabs({
						select:function(event,ui){
							var selected = $(this).tabs("option","selected");
							var touch = ui.index;
							if( selected<0){
								$("#welcomeInfo").toggle("blind",{},150);
								$(ui.panel).toggle("blind",{},150);
								}
							else if(selected==touch){
								$("#welcomeInfo").toggle("blind",{},150);
								$(ui.panel).toggle("blind",{},150);
								}
							else if(selected!=touch){
								$("div#userTabs_title div:nth-child("+(selected+2)+")").hide();
								$("div#userTabs_title div:nth-child("+(touch+2)+")").show();
								}
							}
					});

				}
				else{
					document.getElementById("signUping").src = "http://www.eizia.com/webpic/warning.png";
					document.getElementById("appInfo").innerHTML = "啊偶，注册失败了";
					}
				
			}
		} 
	}


var AJAX_check;

function checkName(userName){
	if(userName.length>2){
		AJAX_check = getAJAXObject();
		if(AJAX_check==null){
			alert ("Browser does not support HTTP Request,Please change your Browser!");
			return;
			}
		document.getElementById("checkNameing").src = "http://www.eizia.com/webpic/ing.gif";
		if(userName){
			var url="http://www.eizia.com/application.php";
			url = url +"?sid="+Math.random();
			AJAX_check.onreadystatechange = checkNameTips;
			AJAX_check.open("POST",url,true);
			AJAX_check.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
			AJAX_check.send("state=checkName"+"&"+"userName="+userName);
			}
		}
	else{
		document.getElementById("checkNameing").src = "http://www.eizia.com/webpic/warning.png";
		document.getElementById("checkNameInfo").innerHTML = "用户名的长度至少是三位";
		}
	}
function checkNameTips(){
	if (AJAX_check.readyState==4 || AJAX_check.readyState=="complete")
		{ 
		xmlDoc = AJAX_check.responseXML;
		var saveModel = xmlDoc.getElementsByTagName("checkName");
		var info = saveModel[0] ? saveModel[0] : false;
		if(info){
			if(info.childNodes[0].childNodes[0].nodeValue=="available"){
				document.getElementById("checkNameing").src = "webpic/correct.png";
				document.getElementById("checkNameInfo").innerHTML = "可以使用";
				}
			else if(info.childNodes[0].childNodes[0].nodeValue=="theSame"){
				document.getElementById("checkNameing").src = "webpic/warning.png";
				document.getElementById("checkNameInfo").innerHTML = "已被使用";
				}
			}
		} 
	}
	
//---------------------------------------------------------------------------------------------
var AJAX_loadDoc;
var AJAX_loadPhp;

function loadDocTo(docUrl,elem,callBack){
	AJAX_loadDoc = getAJAXObject();
	if(AJAX_loadDoc==null){
		alert ("Browser does not support HTTP Request,Please change your Browser!");
		return;
		}
		var url = docUrl +"?sid="+Math.random();
		AJAX_loadDoc.onreadystatechange = function(){afterLoadDoc(elem,callBack)};
		AJAX_loadDoc.open("GET",url,true);
		AJAX_loadDoc.send(null);
	}
function afterLoadDoc(elem,callBack){
	if (AJAX_loadDoc.readyState==4 || AJAX_loadDoc.readyState=="complete")
		{
		elem.innerHTML += AJAX_loadDoc.responseText;
		if(callBack){callBack();}
		} 
	}
	
function loadPhpTo(phpUrl,postValue,elem,callBack){
	AJAX_loadPhp = getAJAXObject();
	if(AJAX_loadPhp==null){
		alert ("Browser does not support HTTP Request,Please change your Browser!");
		return;
		}
		var url = phpUrl +"?sid="+Math.random();
		AJAX_loadPhp.onreadystatechange = function(){afterLoadPhp(elem,callBack)};
		AJAX_loadPhp.open("POST",url,true);
		AJAX_loadPhp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=ASCII");
		AJAX_loadPhp.send(postValue);
	}
function afterLoadPhp(elem,callBack){
	if (AJAX_loadPhp.readyState==4 || AJAX_loadPhp.readyState=="complete")
		{
		elem.innerHTML += AJAX_loadPhp.responseText;
		if(callBack){callBack();}
		} 
	}
	

//---------------------------------------------------------------------------------------------
var AJAX_loadModel;
var AJAX_loadModelInfo;

function loadModel(model_id){
	var model_id = model_id ? model_id : document.getElementById("showingModel").innerHTML;
	AJAX_loadModel = getAJAXObject();
	if(AJAX_loadModel==null){
		alert ("Browser does not support HTTP Request");
		return;
		}
	var url="http://www.eizia.com/loadModel.php"
	url = url +"?sid="+Math.random();
	AJAX_loadModel.onreadystatechange = loadModelTips;
	AJAX_loadModel.open("POST",url,true);
	AJAX_loadModel.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=ASCII");
	AJAX_loadModel.send("model_id="+model_id);
	
	}

function loadModelTips(){
	if (AJAX_loadModel.readyState==4 || AJAX_loadModel.readyState=="complete")
		{ 
		var info = AJAX_loadModel.responseText;
		if(info && document.getElementById("showingModel")){
			e83.e85(info);
			}
		else if(info){
			e110.e112(info);
			loadModelInfo(model_id);
			}
		}
	}


function loadModelInfo(model_id){
	AJAX_loadModelInfo = getAJAXObject();
	if(AJAX_loadModelInfo==null){
		alert ("Browser does not support HTTP Request");
		return;
		}
	var url="http://www.eizia.com/loadModelInfo.php"
	url = url +"?sid="+Math.random();
	AJAX_loadModelInfo.onreadystatechange = loadModelInfoTips;
	AJAX_loadModelInfo.open("POST",url,true);
	AJAX_loadModelInfo.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=ASCII");
	AJAX_loadModelInfo.send("model_id="+model_id);
	
	}

function loadModelInfoTips(){
	if (AJAX_loadModelInfo.readyState==4 || AJAX_loadModelInfo.readyState=="complete")
		{ 
		var xmlinfo = AJAX_loadModelInfo.responseXML;
		var modelInfo = xmlinfo.getElementsByTagName("info");
		if(modelInfo){
			document.getElementById("cubeTitleName").innerHTML = modelInfo[0].childNodes[0].childNodes[0].nodeValue;
			document.getElementById("modelName").value = modelInfo[0].childNodes[0].childNodes[0].nodeValue;
			document.getElementById("modelDescription").value = modelInfo[0].childNodes[1].childNodes[0].nodeValue;
			}
			
			}
		
	}

	
	
function include_js(jsCode) {
	var html_doc = document.getElementsByTagName("head")[0];
	var js = document.createElement("script");
	js.setAttribute("type", "text/javascript");
	js.text = jsCode;
	html_doc.appendChild(js);
	return false;
	}
	
function getAJAXObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
		catch(e){
			// Internet Explorer
			try{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e){
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
						}
			}
	return xmlHttp;
	}
	
var AJAX_incluedJs;
var AJAX_storage;

function downJs(path,callBack){
	AJAX_incluedJs = getAJAXObject();
	if(AJAX_incluedJs==null){
		alert ("Browser does not support HTTP Request");
		return;
		}
	var url = path +"?sid="+Math.random();
	AJAX_incluedJs.onreadystatechange = function(){afterDownJs(callBack);};
	AJAX_incluedJs.open("get",url,true);
	AJAX_incluedJs.send(null);
	}
	
function afterDownJs(callBack){
	if (AJAX_incluedJs.readyState==4 || AJAX_incluedJs.readyState=="complete")
		{ 
		var jsCode = AJAX_incluedJs.responseText;
		include_js(jsCode);
		//开始实例化o3d场景
		callBack();
		} 
	}
	
function storageCondition(id){
	AJAX_storage = getAJAXObject();
	if(AJAX_storage==null){
		alert ("Browser does not support HTTP Request");
		return;
		}
	var path="http://www.eizia.com/storageCondition.php"
	var url = path+"?sid="+Math.random();
	AJAX_storage.open("POST",url,true);
	AJAX_storage.onreadystatechange = afterStorageId;
	AJAX_storage.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf8");
	AJAX_storage.send("model_id="+id
						);
	}
function afterStorageId(){
	if (AJAX_storage.readyState==4 || AJAX_storage.readyState=="complete")
		{ 
			window.location.href = "http://www.eizia.com/edit.html";
			}
	}
